#ifndef _ANY_H_
#define _ANY_H_
#include<memory>
#include<iostream>
class Any
{
public:
 Any()=default;
 ~Any()=default;
 Any(const Any&) = delete;
 Any& operator=(const Any &) =delete;
  Any(Any && )=default;
 Any& operator=( Any&& )=default;
 template<class T>
 Any(T data):base_(new Derive<T>(data)){}

 template<class T>
 T cast_()
 {
    Derive<T> * pd = dynamic_cast<Derive<T>*>(base_.get());
    if(nullptr == pd)
    {
        std::cout<<"type is nomach"<<std::endl; //使用的数据和实例化cast_时的类型不符
    }
    return pd->data_;
 }
private:
   class Base
   {
     public:
      Base()=default;
      virtual ~Base()=default;
   };
   template<class T>
   class Derive :public Base
   {
    public:
     Derive(T data):data_(data){}
      T data_;
   };
private:
   std::unique_ptr<Base> base_;
};
#endif